package file;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import data.DataBig;

public class ParserBig {

	List<DataBig> list;
	double avg;
	int maxuid;
	int maxiid;

	public ParserBig(String dir) throws IOException {
		maxuid = 0;
		maxiid = 0;
		String line;
		double sumTest = 0.0;
		BufferedReader br = new BufferedReader(new FileReader(dir));
		List<DataBig> test = new ArrayList<DataBig>();

		while((line = br.readLine()) != null){

			String[] fields = line.split(",");
			int uid = Integer.parseInt(fields[0]);
			int iid = Integer.parseInt(fields[1]);
			double rat = Double.parseDouble(fields[2]);	
			
			test.add(new DataBig(uid,iid,rat));	
			
			sumTest += rat;
			
			if(uid > maxuid){
				maxuid = uid;
			}
			if(iid > maxiid){
				maxiid = iid;
			}
		}
		br.close();
		
//		System.out.println("Number of ratings in test: "+test.size());
		
		double avgTest = sumTest / test.size();
//		System.out.println("Avg. of ratings in test: "+avgTest);
		
		this.list = test;
		this.avg = avgTest;
	}
	
	public List<DataBig> getList() {
		return list;
	}
	public double getAvg() {
		return avg;
	}

	public int getMaxuid() {
		return maxuid;
	}

	public int getMaxiid() {
		return maxiid;
	}
}
